package wangbaguanlixitong.servlet;

import wangbaguanlixitong.dao.AdminDao;
import wangbaguanlixitong.model.Admin;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "AdminUpdateServlet",urlPatterns = "/adminupdate")
public class AdminUpdateServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

//        response.setContentType("text/html;charset=utf-8");
//        Admin admin = new Admin();
//        AdminDao admindao = new AdminDao();
//        //获取Admin的用户名
//        admin = admindao.getAdminName(request.getParameter("name"));
//        //得到新密码
//        String newpassword = request.getParameter("newpassword");
//        //把得到的新密码发送到数据库并修改密码
//        admin.setUserPw(newpassword);
//        admindao.updatepw(admin);
//        //转发页面
//        request.getRequestDispatcher("admin.jsp").forward(request,response);

        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        //获取前端参数
        String uname = request.getParameter("uname");
        String upwd = request.getParameter("upwd");
        //传入参数
        Admin admin = new Admin();
       admin.setUserName(uname);
       admin.setUserPw(upwd);
        AdminDao admindao = new AdminDao();
        admindao.GetReset(admin);

        request.getRequestDispatcher("admin.jsp").forward(request, response); //成功后跳转到登录


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("admin.jsp").forward(request,response);
    }
}
